package dobest.ray.com.jiongjiong.activity.login.dataInport.questionair;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.dobest.ray.corelibs.utils.ViewHolder;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import dobest.ray.com.jiongjiong.R;
import dobest.ray.com.jiongjiong.bean.QuestionairCallBackBean;
import dobest.ray.com.jiongjiong.bean.QuestionnairBean;
import dobest.ray.com.jiongjiong.callback.A2FCallBack;
import dobest.ray.com.jiongjiong.views.seekbar.SeekBarLayout;

public class QuestionnairAdapter extends BaseAdapter {
    private Context context;
    private LayoutInflater inflater;
    private List<QuestionnairBean> data = new ArrayList<QuestionnairBean>();
    private int index = 0;
    private Set<Integer> numClick = new HashSet<Integer>();

    private A2FCallBack<QuestionairCallBackBean> callBack;

    public QuestionnairAdapter(Context context, int index, A2FCallBack<QuestionairCallBackBean> callBack) {
        this.context = context;
        this.inflater = LayoutInflater.from(context);
        this.index = index;
        this.callBack = callBack;
        init();
    }

    private void init() {
        switch (index) {
            case 1:
                data.add(new QuestionnairBean(21, "读写座椅是否与身高匹配，感觉舒适？",
                        R.mipmap.img_icon_desk, 0, "没关注", "", "很舒适"));
                data.add(new QuestionnairBean(22, "看近时照明是否柔和不刺眼，感觉舒适？",
                        R.mipmap.img_icon_bulb, 0, "没关注", "", "很舒适"));
                data.add(new QuestionnairBean(23, "读写时台灯是否放置在非惯用手方向？",
                        R.mipmap.img_icon_desk, 0, "没注意", "", "一直是"));
                data.add(new QuestionnairBean(24, "读写时能够保持正确握笔与用眼习惯？",
                        R.mipmap.img_icon_book, 0, "没关注", "", "一直是"));
                break;
            case 2:
                data.add(new QuestionnairBean(25, "平均每天看电子设备的时间？",
                        R.mipmap.img_icon_ipad, 0, "0小时", "", "3小时", 0, 3, true));
                data.add(new QuestionnairBean(26, "平均一般连续用眼多久休息远眺？",
                        R.mipmap.img_icon_eye, 0, "不休息", "", "30分钟", 0, 30, true));
                data.add(new QuestionnairBean(27, "平均每天近距离用眼时间？（读书、写字和看电子设备等）",
                        R.mipmap.img_icon_drawp, 0, "0.5小时", "", "8小时", 0.5f, 8,
                        true));
                data.add(new QuestionnairBean(28, "是否存在习惯性过近用眼？",
                        R.mipmap.img_icon_phone, 0, "很少", "", "习惯性"));
                break;
            case 3:
                data.add(new QuestionnairBean(29, "平均每天户外运动时间？",
                        R.mipmap.img_icon_run, 0, "0小时", "", "3小时", 0, 3, true));
                data.add(new QuestionnairBean(30, "平均每天睡眠时间？",
                        R.mipmap.img_icon_sleep, 0, "5小时", "", "10小时", 5, 10,
                        true));
                data.add(new QuestionnairBean(31, "是否长期饮食均衡？",
                        R.mipmap.img_icon_whaterma, 0, "没注意", "", "一直是"));
                data.add(new QuestionnairBean(32, "是否每天坚持做眼肌操或球类运动？",
                        R.mipmap.img_icon_pp, 0, "很少", "", "一直是"));
                break;

            default:
                break;
        }

    }

    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public QuestionnairBean getItem(int arg0) {
        return data.get(arg0);
    }

    @Override
    public long getItemId(int arg0) {
        return arg0;
    }

    @Override
    public View getView(int position, View view, ViewGroup arg2) {
        final QuestionnairBean bean = data.get(position);
        if (view == null) {
            view = inflater.inflate(R.layout.item_questionnair_list, null);
        }
        TextView tv_title = ViewHolder.get(view, R.id.tv_title);
        tv_title.setText(bean.title);

        ImageView iv_show_icon = ViewHolder.get(view, R.id.iv_show_icon);
        iv_show_icon.setImageResource(bean.resId);

        SeekBarLayout sbl_scale = ViewHolder.get(view, R.id.sbl_scale);
        sbl_scale.setSpecialData(bean.isShowScale, bean.min, bean.max);
        sbl_scale.setData(bean.scale, bean.scaleNotice, bean.scaleNoticeNormal,
                bean.scaleNoticeSerious);
        sbl_scale.setScaleCallback(new SeekBarLayout.ScaleCallBack() {

            @Override
            public void onScaleChanged(int scale) {
                bean.scale = scale;
                numClick.add(bean.id);
                if (numClick.size() >= 2) {
                    if (callBack != null) {
                        callBack.getActivityData(new QuestionairCallBackBean("survey_current", index));
                    }
//					EventBus.getDefault().post(
//							new EventbusBean("survey_current", index));
                }
            }
        });
        return view;
    }

    public List<QuestionnairBean> getData() {
        return data;
    }
}
